package cn.yqx.bankshop.goods.service.impl;

import cn.yqx.bankshop.goods.dao.BuGoodsDetatilParaMapper;
import cn.yqx.bankshop.goods.dao.BuGoodsMapper;
import cn.yqx.bankshop.goods.pojo.BuGoods;
import cn.yqx.bankshop.goods.pojo.BuGoodsDetatilPara;
import cn.yqx.bankshop.goods.pojo.BuGoodsDetatilParaExample;
import cn.yqx.bankshop.goods.pojo.BuGoodsExample;
import cn.yqx.bankshop.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    BuGoodsMapper mapper ;
    @Autowired
    BuGoodsDetatilParaMapper paraMapper ;

    public BuGoods findById(Long goodId) {
        BuGoods buGoods= mapper.selectByPrimaryKey(goodId) ;
        //buGoods.setGoodsIntroductStr();
        return buGoods;
    }

    @Override
    public List<BuGoods> selectGoodsList(HashMap<String,Object> map) {
        return mapper.selectGoodsList(map);
    }

    @Override
    public List<Map<String, Object>> findMainBusiness(Long supplierId) {
        return mapper.findMainBusiness(supplierId);
    }

    @Override
    public List<BuGoods> findGoodsByIds(List<Long> ids) {
        BuGoodsExample example = new BuGoodsExample() ;
        example.or().andIdIn(ids) ;
        return mapper.selectByExample(example);
    }

    @Override
    public List<BuGoods> selectAll() {

        return mapper.selectAll();
    }

    @Override
    public List<BuGoods> findGoods() {
        return mapper.findGoods();
    }

    @Override
    public int updateSupplierName(String supplierName , Long goodsId) {
        BuGoodsExample example = new BuGoodsExample() ;
        example.or().andIdEqualTo(goodsId) ;
        BuGoods buGoods = new BuGoods() ;
        buGoods.setSupplierName(supplierName);
        return mapper.updateByExampleSelective(buGoods,example) ;
    }

    @Override
    public int findGoodsNumBySupplierId(Long supplier) {
        return mapper.findGoodsNumBySupplierId(supplier);
    }

    @Override
    public List<Map<String, Object>> statisticsGoodsByCategory(List<Map<String, Object>> goodsList) {
        return mapper.statisticsGoodsByCategory(goodsList);
    }

    @Override
    public List<Map<String, Object>> statisticsByCategory(List<Map<String, Object>> goodsList) {
        return mapper.statisticsByCategory(goodsList);
    }

    @Override
    public List<BuGoodsDetatilPara> getGoodDetatilParaList(Long goodId) {
        BuGoodsDetatilParaExample example = new BuGoodsDetatilParaExample() ;
        example.or().andGoodsIdEqualTo(goodId.intValue()) ;
        return paraMapper.selectByExample(example);
    }

}
